package com.threebrothers.i_video.test

import androidx.lifecycle.viewModelScope
import com.threebrothers.lib_mvi.base.BaseViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch

class MyViewModel : BaseViewModel<MyIntent>() {
    private val bannerDataStateFlow = MutableStateFlow<MyState>(MyState.Loading)
    val bannerDataStateFlow_ = bannerDataStateFlow.asStateFlow()
    /**
     * 根据不同的意图完成不同的处理
     */
    override fun handleIntent() {
        viewModelScope.launch {
            intents.consumeAsFlow().collect{
                when(it){
                    is MyIntent.GetBannerData ->{getBannerData()}
                    is MyIntent.GetVideoData ->{getVideoData(it)}
                }
            }
        }
    }

    fun getBannerData() {
        viewModelScope.launch {
            //网络请求更新状态流
            bannerDataStateFlow.value = MyState.Success("数据。。。。。。。。。。。。。。")
        }
    }


    private fun getVideoData(it: MyIntent.GetVideoData) {

    }
}
